/*

COPYRIGHT 2009 NARESHKUMAR RAO
This software is distributed under the terms of the GNU General Public License

This file is part of JSCMD.

JSCMD is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

JSCMD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JSCMD.  If not, see http://www.gnu.org/licenses/.

*/

//JSCMD JavaScript Version 1.2

alert('Welcome To TechnoFlash Command Prompt.\nThis Program Is Made By Nareshkumar Rao');

if(navigator.userAgent.match("MSIE"))
{

	if(confirm("You are currently using Internet Explorer.\n Internet Explorer is currently not supported by JSCMD.\nHowever, you may still try it out if you wish.")==false)
	{
		document.location="http://code.google.com/p/jscmd";
	}

}

document.onkeyup = handleCmd;

var getDomain = document.domain.toUpperCase();

if(getDomain=="")
{
	getDomain = "C:\\RUNNING LOCALLY>";
}else{
	getDomain = "C:\\"+document.domain.toUpperCase()+">";
}

var promptTitle = getDomain;



function parseCMD()
{
	var comm = fta.value.substring(promptTitle.length,fta.value.length);
	
	sta.scrollTop=sta.scrollHeight;
	//BEGINS BASIC PARSING

	bcount=0;

	if(comm.substring(0,5)=="echo " || comm.substring(0,5)=="ECHO ")
	{
	
		sta.value+="\n"+comm.substring(5,comm.length);
		
	}else if(comm.substring(0,3)=="cls" || comm.substring(0,3)=="CLS")
	{
	
		sta.value="";
		
	}else if(comm.substring(0,8)=="ipconfig" || comm.substring(0,8)=="IPConfig")
	{
	
		sta.value+="\nObviously You're Connected To The Internet, How Do You Think You Can Actually See This Page? Unless, You're Viewing This Locally.";
		
	}else if(comm.substring(0,5)=="color" || comm.substring(0,5)=="Color")
	{
	
		sta.style.background=comm.substring(6,comm.indexOf(","))
		sta.style.color=comm.substring(comm.indexOf(",")+1,comm.length)
		
	}else if(comm.substring(0,2)=="^G")
	{
	
		sta.value+="\nBLEEEP!";
		bcount++;
		
		if(bcount>5)
		{
			sta.value+="ENOUGH BLEEPING ALREADY";
		}
		
	}else if(comm.substring(0,4)=="help" || comm.substring(0,1)=="?" || comm.substring(0,4)=="Help")
	{
	
		document.location="http://code.google.com/p/jscmd/wiki/Functions";
	
	}else if(comm.substring(0,6)=="prompt" || comm.substring(0,6)=="Prompt")
	{
		if(comm.substring(7,10)=="def" || comm.substring(7,10)=="Def")
		{
		promptTitle = getDomain;
		}else{
		promptTitle = comm.substring(7,comm.length-1);
		}
		
	}else if(comm.substring(0,4)=="time" || comm.substring(0,4)=="Time")
	{
		var today = new Date();
		var  gHour = today.getHours();
		var gMin = today.getMinutes();
		var gSec = today.getSeconds();
		var gMil = today.getMilliseconds();
		
		sta.value+="\nThe current time is: "+gHour+":"+gMin+":"+gSec+"."+gMil;
		
	}else if(comm.substring(0,5)=="title" || comm.substring(0,5)=="Title")
	{
		
		document.title=comm.substring(6,comm.length);
		
	}else if(comm.substring(0,6)=="search" || comm.substring(0,6)=="Search")
	{
		if( comm.match("/I /Y") || comm.match("/Y /I") )
		{
			
			document.location = "http://images.search.yahoo.com/search/images?p="+comm.substring(12,comm.length);
			
		}else if(comm.match("/Y"))
		{
			document.location = "http://search.yahoo.com/search?p="+comm.substring(9,comm.length);
		}else if(comm.match("/I"))
		{
			document.location="http://images.google.com/images?q="+comm.substring(9,comm.length);
			
		}else{
			document.location = "http://www.google.com/search?q="+comm.substring(7,comm.length);
		}
		
	}else{
	
		var bgcol = sta.style.background;
		sta.style.background="red";
		setTimeout(function(){sta.style.background=bgcol}, 200);
		sta.value+="\n\'"+comm.substring(0,comm.length-1)+"' is not recognized as an internel or external command, operable program or batch file.";
		
	}

}

function handleCmd(e)
{

	var keyId= (window.event) ? event.keyCode : e.keyCode;
	if(keyId==13)
		{

		parseCMD();
		fta.value=promptTitle;

	}
}

function initCMD()
{
	fta.style.width=window.innerWidth;
	fta.style.height=window.innerHeight/2;
	
	sta.style.width=window.innerWidth;
	sta.style.height=window.innerHeight/2;
	sta.style.top=window.innerHeight/2;

	fta.value=promptTitle;
}

function noDelete()
{
	if(fta.value.substring(0,promptTitle.length)!=promptTitle)
	{
		fta.value=promptTitle;
	}
}